﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class GetCircleAdvertList : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            CircleAdvertOutParam result = new CircleAdvertOutParam();
            CircleAdvertInParam param = new CircleAdvertInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            {
                param = inParam as CircleAdvertInParam;
                if (!string.IsNullOrEmpty(param.community_type) && param.community_type != "0" && param.community_type != "1" && param.community_type != "2")
                {
                    result.code = "0";
                    result.desc = "群类型只能为0(固定群)，1(临时群)，2(所有)";

                    isFlag = false;
                }　

                if(isFlag)
                {
                    DataSet ds = InterfaceHelper.GetCircleAdvertList(param.community_type);
                    if (ds != null && ds.Tables[0].Rows.Count > 0)
                    { 
                        CircleAdvert itemTemp; 
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            itemTemp = new CircleAdvert();
                            itemTemp.ad_id = dr["ID"].ToString();
                            itemTemp.circleType = dr["circleType"].ToString(); 
                            itemTemp.photo_bar = CommonUtils.AppAddress + SXT.Utility.FileServer.QueryFileUrl(dr["photo_min"].ToString());
                            result.data.list.Add(itemTemp);
                        }
                    }  
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-GetCircleAdvertList", SerializeHelper.JsonSerializer<CircleAdvertInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<CircleAdvertInParam, CircleAdvertOutParam>();
            else
                SafeProcessRequest<CircleAdvertInParam, CircleAdvertOutParam>();
        }
    }

    #region 请求参数
    public class CircleAdvertInParam
    {
        /// <summary>
        /// 必填，	用户ＩＤ
        /// </summary>
        public string user_id
        { get; set; } 

        /// <summary>
        /// 必填 圈子类型
        /// </summary>
        public string community_type
        { get; set; }　
    }
    #endregion

    #region 结果参数
    public class CircleAdvertOutParam
    {
        public CircleAdvertOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new CircleAdvertList();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        /// <summary>
        /// 有效广告列表
        /// </summary>
        public CircleAdvertList data
        { get; set; }
    }

    public class CircleAdvertList
    {
        public CircleAdvertList()
        {　
            list = new List<CircleAdvert>();
        }

        public List<CircleAdvert> list { get; set; }　
    }
     
    /// <summary>
    /// 有效广告列表
    /// </summary>
    public class CircleAdvert
    { 
        /// <summary>
        ///	广告ID	
        /// </summary>
        public string ad_id
        { get; set; }
        /// <summary>
        ///	广告横幅小图片	
        /// </summary>
        public string photo_bar
        { get; set; }
        /// <summary>
        ///	
        /// </summary>
        public string circleType
        { get; set; }　
    }
    #endregion 
}